﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using FOModels.ProductFAQ;
namespace DataAccess.ProductFAQ
{
    public class ProductFAQDAL
    {
        private SQLDataAccess db;
        public ProductFAQDAL()
        {
            db = new SQLDataAccess();
        }
        public DataTable gettop1faq()
        {
            return db.exeSelect("select top 1 * from ProductFAQ order by ProductFAQID desc");
        }
        public DataTable getfaqbyproid(int ProductID, int langid)
        {
            return db.exeSelect("Select * from ProductFAQ p join ProductFAQLang pl on p.ProductFAQID = pl.ProductFAQID join Language la on pl.LangID = la.ID where LangID =" + langid + "  and ProductID = " + ProductID + "");
        }
        public DataTable getfaqbyid(int ProductFAQID, int langid)
        {
            return db.exeSelect("Select * from ProductFAQ p join ProductFAQLang pl on p.ProductFAQID = pl.ProductFAQID where LangID =" + langid + "  and p.ProductFAQID = " + ProductFAQID + "");
        }
        public int UpdateFAQ(ProductFAQModels models)
        {
            return db.exeUpdate("update ProductFAQ set FAQTitles = N'" + models.FAQTitles + "' where ProductFAQID = " + models.ProductFAQID + "");
        }
        public int UpdateFAQLang(ProductFAQModels models, int langid)
        {
            return db.exeUpdate("update ProductFAQLang set FAQTitles = N'" + models.FAQTitles + "',FAQAnwers = N'" + models.FAQAnwers + "' where ProductFAQID = " + models.ProductFAQID + " and LangID = " + langid + "");
        }
        public int InsertFAQ(ProductFAQModels models)
        {
            return db.exeUpdate("insert into ProductFAQ(FAQTitles,ProductID) values (N'" + models.FAQTitles + "'," + models.ProductID + ")");
        }
        public int InsertFAQLang(ProductFAQModels models, int langid)
        {
            return db.exeUpdate("insert into ProductFAQLang values (" + models.ProductFAQID + "," + langid + ",N'" + models.FAQTitles + "',N'" + models.FAQAnwers + "')");
        }
        public int DeleteFAQ(int ProductFAQID)
        {
            return db.exeUpdate("Delete from ProductFAQ where ProductFAQID = " + ProductFAQID + "");
        }
        public int DeleteFAQLang(int ProductFAQID)
        {
            return db.exeUpdate("Delete from ProductFAQLang where ProductFAQID = " + ProductFAQID + "");
        }

    }
}
